package portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import portal.mybatis.dao.JobEntity;
import portal.mybatis.dao.service.JobDetailService;
import portal.mybatis.page.Page;

@RestController
public class JobController extends BaseController{
	@Autowired
	JobDetailService jobDetailService;
	@RequestMapping(value="/job/page",method=RequestMethod.GET)
	public Page<JobEntity> getPage(long pageSize,long currentPage,String searchText,String sort,String sortOrder){
		if(pageSize<0)
			pageSize=10;
		if(currentPage<=0)
			currentPage=1;
		Page<JobEntity> p=jobDetailService.getPage(new Page<JobEntity>(pageSize,currentPage-1,searchText,sort ,sortOrder));
		return p;
	}
	@RequestMapping(value="/job/{jobId}",method=RequestMethod.POST)
	public JobEntity getJobById(@PathVariable("jobId")String jobId){
		return jobDetailService.selectJobById(jobId);
	}
	
	@RequestMapping(value="/job/list/{nodeName}",method=RequestMethod.GET)
	public Page<JobEntity> getJobListByNode(@PathVariable("nodeName")String nodeName,long pageSize, long offset,String sort,String sortOrder,String searchText){
		if(nodeName==null){
			return null;
		}
		//if(currentPage)
		return jobDetailService.selectJobByNode(nodeName, new Page<JobEntity>(pageSize,offset,searchText,sort ,sortOrder));
	}
}
